package com.asiainfo.indb.control;

/**
 * @author zym
 * @date 2019-10-19 11:12
 */
public class ThreadFactory {

    private static final java.util.concurrent.ThreadFactory FACTORY = r -> {
        Thread thread = new Thread(r);
        thread.setDaemon(true);
        return thread;
    };

    /**
     * 启动任务
     *
     * @param name 线程名
     * @param task 任务
     */
    public static void run(String name, Runnable task) {
        if (name != null && task != null) {
            Thread thread = FACTORY.newThread(task);
            thread.setName(name);
            thread.start();
        }
    }

}